﻿Imports DataAccess
Imports DTO

Public Class BSMonthly

    Public Sub New(ByVal serverName As String)

        ' config server name
        DAMonthly.ConfigServerName(serverName)

    End Sub

    ''' <summary>
    ''' Get all monthlies by organization no
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetMonthly(ByVal organNo As String) As DataTable

        Return DAMonthly.GetMonthly(organNo)

    End Function


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="listMonthly"></param>
    ''' <remarks></remarks>
    Public Sub SortMonthly(ByRef listMonthly As ArrayList)

        For i As Integer = 0 To listMonthly.Count - 1

            For j As Integer = i + 1 To listMonthly.Count - 1

                If Integer.Parse(DirectCast(listMonthly(i), DTOMonthly).ExFromProperty) > Integer.Parse(DirectCast(listMonthly(j), DTOMonthly).ExFromProperty) Then

                    Dim temp As Object = listMonthly(i)

                    listMonthly(i) = listMonthly(j)

                    listMonthly(j) = temp

                End If

            Next

        Next

    End Sub


    ''' <summary>
    ''' subtract month to 1
    ''' </summary>
    ''' <param name="month"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SubtractMonth(ByVal month As Integer) As Integer

        Dim m As Integer = month Mod 100

        Dim y As Integer = month \ 100

        If m = 1 Then

            Return (y - 1) * 100 + 12

        Else

            Return y * 100 + m - 1

        End If

    End Function


    ''' <summary>
    ''' Delete all monthly in database
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteAllMonthly(ByVal organNo As String) As Boolean

        If DAMonthly.DeleteAllMonthly(organNo) <> 0 Then

            Return True

        Else

            Return False

        End If

    End Function

    ''' <summary>
    ''' Add new monthly to database
    ''' </summary>
    ''' <param name="dtoMonthly"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AddMonthly(ByVal dtoMonthly As DTOMonthly) As Boolean

        If DAMonthly.AddMonthly(dtoMonthly) <> 0 Then

            Return True

        Else

            Return False

        End If

    End Function

End Class
